;;;;;;;;;;;;;;;;;;;;  gnus plugins  ;;;;;;;;;;;;;;;;;;;;
(require 'smtpmail)
(require 'nnimap)
(require 'starttls)
(require 'pop3)
;;;;;;;;;;;;;;;;;;;;  coding  ;;;;;;;;;;;;;;;;;;;;
(eval-after-load "mm-decode"
  '(progn
     (add-to-list 'mm-discouraged-alternatives "text/html")
     (add-to-list 'mm-discouraged-alternatives "text/richtext")))
(setq mm-coding-system-priorities '(iso-8859-1 gb2312 iso-8859-15 utf-8))
(setq gnus-default-charset 'gb2312
      gnus-group-name-charset-group-alist '((".*" . gb2312))
      gnus-summary-show-article-charset-alist
      '((1 . gb2312)
        (2 . gbk)
        (3 . big5)
        (4 . utf-8)
        (5 . cn-gb-2312)
        (6 . chinese-iso-8bit))
      gnus-newsgroup-ignored-charsets
      '(unknown-8bit x-unknown iso-8859-1))
(setq gnus-summary-show-article-charset-alist
      '((1 . utf-8)
        (2 . gb2312)
        (3 . gbk)
        (4 . big5)
        (5 . iso-8859-1)
        (6 . iso-8859-15)
))

;;;;;;;;;;;;;;;;;;;;  mail setting  ;;;;;;;;;;;;;;;;;;;;
(setq send-mail-function 'smtpmail-send-it
      message-send-mail-function 'smtpmail-send-it
      smtpmail-starttls-credentials '(("smtp.gmail.com" 587 nil nil))
      smtpmail-auth-credentials (expand-file-name "~/.authinfo")
      smtpmail-default-smtp-server "smtp.gmail.com"
      smtpmail-smtp-server "smtp.gmail.com"
      smtpmail-smtp-service 587
      smtpmail-debug-info t)
;; (setq pop3-leave-mail-on-server nil)

;;;;;;;;;;;;;;;;;;;;  gnus setting  ;;;;;;;;;;;;;;;;;;;;
(setq gnus-read-newsrc-file nil  gnus-save-newsrc-file nil)
(setq gnus-select-method '(nntp "news.individual.net"))
(setq gnus-default-subscribed-newsgroups
      '( "cn.comp.os.linux"
      "gnu.emacs.help" "cn.comp.os.linux"))
(setq gnus-secondary-select-methods 
      '((nnimap "gmail"
                  (nnimap-address "imap.gmail.com")
                  (nnimap-server-port 993)
                  (nnimap-stream ssl))
        (nnfolder "")))
(setq gnus-thread-sort-functions
      '((not gnus-thread-sort-by-date)
        (not gnus-thread-sort-by-number)))
(setq gnus-group-name-charset-method-alist
      '(((nnimap "gmail") . utf-8) ((nnimap "TUM") . utf-8)))
(gnus-add-configuration '(article
                          (vertical 1.0
                                    (summary .4 point)
                                    (article 1.0))))
(setq gnus-posting-styles
      '((".*"
         (name user-full-name)
         (address user-mail-address)
         (eval (setq mm-coding-system-priorities
                     '(iso-8859-1 gb2312 iso-8859-15 utf-8)))
         (signature-file "~/.signature")
         (x-url emax-web))
        ("^de\\."
         (name emax-id)
         (address user-mail-address)
         (eval (setq mm-coding-system-priorities
                     '(iso-8859-1 iso-8859-15 utf-8))))
        ("^cn\\."
         (name emax-id)
         (address (concat emax-id"@newsmth.net"))
         (eval (setq mm-coding-system-priorities
                     '(gb2312 iso-8859-1 utf-8))))
        ("^tw\\.comp"
         (name emax-id)
         (address (concat emax-id "@ptt.cc"))
         (eval (setq mm-coding-system-priorities
                     '(big5 iso-8859-1 utf-8))))))

;;;;;;;;;;;;;;;;;;;;  gnus notify  ;;;;;;;;;;;;;;;;;;;;
(require 'gnus-notify+)
(add-hook 'gnus-summary-exit-hook 'gnus-notify+)
(add-hook 'gnus-group-catchup-group-hook 'gnus-notify+)
(add-hook 'mail-notify-pre-hook 'gnus-notify+)
(gnus-demon-add-handler 'gnus-demon-scan-mail 2 t)
(gnus-demon-add-handler 'gnus-demon-scan-news 2 t)
(setq message-cite-function 'message-cite-original-without-signature)
(add-to-list 'gnus-secondary-select-methods '(nnmaildir "mymailbox" (directory "~/Mail")))
(setq gnus-message-archive-method "nnmaildir+mymailbox:" 
           gnus-update-message-archive-method t 
           gnus-message-archive-group '((if (message-news-p) 
           "nnmaildir+mymailbox:sent-news" "nnmaildir+mymailbox:sent-mail")))

;;;;;;;;;;;;;;;;;;;;  jabber setting  ;;;;;;;;;;;;;;;;;;;;
(setq jabber-account-list '(("schulei.chu@gmail.com"
                              (:network-server . "talk.google.com")
                              (:port . 5223)
                              (:connection-type . ssl))))
(add-hook 'jabber-chat-mode-hook 'goto-address)
(require 'autosmiley)
(add-to-list 'smiley-regexp-alist '("\\(:-?]\\)\\W" 1 "forced"))
(add-to-list 'smiley-regexp-alist '("\\s-\\(:-?/\\)\\W" 1 "wry"))
(add-to-list 'smiley-regexp-alist '("\\(:-?(\\)\\W" 1 "sad"))
(add-to-list 'smiley-regexp-alist '("\\((-?:\\)\\W" 1 "reverse-smile"))
(add-to-list 'smiley-regexp-alist '("\\(:-?D\\)\\W" 1 "grin"))
(add-to-list 'smiley-regexp-alist '("\\(:-?P\\)\\W" 1 "poke"))
(add-hook 'jabber-chat-mode-hook 'autosmiley-mode)
(setq abber-vcard-avatars-retrieve nil)
(setq jabber-history-enabled t)
(setq jabber-activity-query-unread t)
(setq jabber-roster-line-format "  %c %-25n %u %-8s  %S")
(defun jabber-start ()
  "Handle the jabber connection startup. If it's call and there
  isn't a buffer named *-jabber-* lunchs jabber-connect,
  otherwise opens a new frame named with *-jabber-* as the
  buffer. In the case there's alredy the byffer and the frame, it
  doesn't do anything"
  (interactive)
  (if (not (member "*-jabber-roster-*" (mapcar (function buffer-name) (buffer-list))))
	  (jabber-connect-all)
	(if (not (member "jabber" (mapcar #'(lambda(x) (frame-parameter x 'name))
					  (frame-list))))
	(progn
	  (select-frame (make-frame '((name . "jabber")
					  (minibuffer . t))))
	  (switch-to-buffer "*-jabber-roster-*"))
	  )))
(defun jabber-stop ()
  "Disconnect from jabber doing some cleaning"
  (interactive)
  (switch-to-buffer "*-jabber-roster-*")
  (kill-buffer nil))




;;;;;;;;;;;;;;;;;;;;  junk  ;;;;;;;;;;;;;;;;;;;;
;; (setq user-full-name user-full-name)
;; (setq user-mail-address "zleinter@yahoo.com.cn")
;; (setq gnus-select-method '(nntp "freenews.netfront.net"))
;; (setq gnus-select-method '(nntp "freetext.usenetserver.com"))
;; (setq gnus-select-method '(nntp "news.cn99.com"))
;;   (add-to-list 'gnus-secondary-select-methods '(nntp "news.gnus.org"))
;;   (add-to-list 'gnus-secondary-select-methods '(nntp "perl.org" (nntp-address "nntp.perl.org")))
;; (setq gnus-message-archive-method
;;       '(nnfolder "archive"
;;                  (nnfolder-inhibit-expiry t)
;;                  (nnfolder-active-file "~/Mail/sent-mail/active")
;;                  (nnfolder-directory "~/Mail/sent-mail/")))
;; (add-to-list 'gnus-secondary-select-methods 
;;              )
;;(setq smtpmail-starttls-credentials nil)
;;(setq nnimap-stream nil)
;;(setq gnus-use-demon t)
;;(gnus-demon-init)
;;(gnus-compile)
;;(gnus-demon-add-handler 'gnus-demon-update-group-buffer 1 nil)
;;(require 'gnus-notify)
;; (setq jabber-username "schuleichu" ;; notice: leave off the @gmail.com
;;       jabber-server "gmail.com"     ;; this is a part of your user ID, not a part of the server you will connect to.
;;       jabber-network-server "talk.google.com"  ;; this is the actual server to connect to
;;       jabber-port 5223
;;       jabber-connection-type 'ssl)
;; (setq send-mail-function 'smtpmail-send-it
;;       message-send-mail-function 'smtpmail-send-it
;;       smtpmail-starttls-credentials '(("smtp.mail.yahoo.com" 25 nil nil))
;;       smtpmail-auth-credentials (expand-file-name "~/.authinfo")
;;       smtpmail-default-smtp-server "smtp.mail.yahoo.com"
;;       smtpmail-smtp-server "smtp.mail.yahoo.com"
;;       smtpmail-smtp-service 25
;;       smtpmail-debug-info t)
;; (nnimap "TUM"
        ;;         (nnimap-address "mail.in.tum.de")
        ;;         (nnimap-server-port 143)
        ;;         (nnimap-stream starttls))
        ;; (nnimap "yahoo"
        ;;           (nnimap-address "imap.mail.yahoo.com")
        ;;           (nnimap-server-port 143)
        ;;           (nnimap-stream ssl))
                             ;; (:port . 443)
                             ;; (:password . "")
                             ;; (:password . "")                             
;; (setq send-mail-function 'smtpmail-send-it
;;       message-send-mail-function 'smtpmail-send-it
;;       smtpmail-starttls-credentials '(("mail.in.tum.de" 25 nil nil))
;;       smtpmail-auth-credentials (expand-file-name "~/.authinfo")
;;       smtpmail-default-smtp-server "mai.in.tum.de"
;;       smtpmail-smtp-server "mail.in.tum.de"
;;       smtpmail-smtp-service 25
;;       smtpmail-debug-info t)
;; (setq smtpmail-starttls-credentials '(("smtp.gmail.com" 587 nil nil))
;;       smtpmail-smtp-server "smtp.gmail.com"
;;       smtpmail-default-smtp-server "smtp.gmail.com"
;;       send-mail-function 'smtpmail-send-it
;;       message-send-mail-function 'smtpmail-send-it
;;       smtpmail-smtp-service 587
;;       )
;; (add-to-list 'gnus-secondary-select-methods '(nnfolder ""))
